public class Solution2 {
    public SingleList.ListNode detectCycle(SingleList.ListNode head) {
        if (head == null) {
            return null;
        }
        SingleList.ListNode fast = head;
        SingleList.ListNode slow = head;
        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow) {
                break;
            }
        }
        if(fast == null || fast.next == null) {
            return null;
        }
        fast = head;
        while(fast != slow) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}